﻿
Partial Class WebForm_ManageExcelUpdateV3
    Inherits System.Web.UI.Page

#Region "事件"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.BindDDLUploadType()
            Me.BindVersion()
            Me.BindDDLDivision()
            Me.BindDDLSignature()
            Me.BindDDLEdition()
            Me.BindDDLCustomerGroup()
        End If
    End Sub

    Protected Sub ddlUploadType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlUploadType.SelectedIndexChanged
        Me.BindVersion()
    End Sub

    Protected Sub ddlDivision_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDivision.SelectedIndexChanged
        Me.BindDDLSignature()
        Me.BindDDLCustomerGroup()
    End Sub

    Protected Sub ddlSignature_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSignature.SelectedIndexChanged
        Me.BindDDLCustomerGroup()
    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        If Not FileUpload1.HasFile Then
            MyObj.ShowMessage("no file")
            Return
        ElseIf IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper() <> ".XLS" AndAlso IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper() <> ".XLSX" Then
            MyObj.ShowMessage("Import failed!!Please select the file extension (xls/xlsx) file!!")
            Return
        End If

        '檢查資料表是否存在
        Dim TableName As String = Me.HeaderTB & Me.ddlVersion.SelectedValue
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        sql.AppendFormat("Select * from sysobjects where name='{0}'", TableName)
        If Not dat.GetData(sql.ToString()).Rows.Count > 0 Then
            MyObj.ShowMessage("Table missed.")
            Return
        End If

        '檢查此版本的Signature是否已經被Locked
        Dim vManager As New VersionManager(Me.ddlVersion.SelectedValue.Replace("SFReport", ""), Me.ddlSignature.SelectedValue, Me.HeaderTB)
        If vManager.Locked = True Then
            MyObj.ShowMessage("Version Locked.")
            Return
        End If

        '上傳暫存檔
        Dim clsRandom As New clsRandom()
        Dim newName As String = Server.MapPath("~/") & "/tmp/" & clsRandom.Generate()
        FileUpload1.PostedFile.SaveAs(newName)

        Dim ExcelImportCheck As New ExcelImportCheck()
        Dim dt As New Data.DataTable

        '檢查工作表名稱
        Try
            If ExcelImportCheck.LoadData(dt, newName, "SFUpload", IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper()) = False Then
                Return
            End If
        Catch ex As Exception
            MyObj.ShowMessage("Please check the file format!!!")
            Exit Sub
        End Try


        '重新命名欄位名稱及清空值
        Dim MonthAdd As Integer = 0
        Dim MonthCount As Integer
        Dim ErrorCount As Integer = 0
        Dim FilterValue As String = ""
        '存月份欄位字串
        Dim MonthString As String = ""
        Dim MonthScope As Integer = 0
        Dim ScopeValue As Integer = 0
        Dim TempDate As Date
        Dim GetMonth As String = ""
        Dim MonthCompare As String = ""

        Dim BaseColumns As Integer = 2 '非月份欄位有2欄
        '如果月份欄位名稱填入非日期或是為F開頭的欄位,則直接刪掉該欄位
        For i As Integer = dt.Columns.Count - 1 To BaseColumns Step -1
            If Not IsDate(dt.Columns(i).ColumnName) Then
                If Left(dt.Columns(i).ColumnName.ToString(), 1) = "F" Then
                    dt.Columns.RemoveAt(i)
                Else
                    MyObj.ShowMessage("Column [{0}] is out of scope.", dt.Columns(i).ColumnName)
                    Return
                End If
            End If
        Next

        If IsNumeric(TableName.Replace(Me.HeaderTB & "SFReport", "")) Then
            'MonthCount = DateTime.Now.Month
            MonthCount = Right(TableName, 2)
        Else
            If TableName.IndexOf("B") <> -1 Then
                MonthCount = 1
            Else
                Dim tcManager As New TCReportReferManager(Me.ddlSignature.SelectedValue, TableName.Replace(Me.HeaderTB & "SFReport", "TCReport"))
                MonthCount = Right(tcManager.GetCurrent(), 2)
            End If

            MonthCount = IIf(MonthCount = 0, 1, MonthCount)
        End If
        TempDate = New Date(Left(TableName.Replace(Me.HeaderTB & "SFReport", ""), 4), MonthCount, 1)
        MonthScope = TempDate.AddMonths(14).Month

        ScopeValue = 12 - MonthScope + 14 + 2 + 1 '+1是加回原本的月份

        For i As Integer = 2 To dt.Columns.Count - 1
            MonthCompare = dt.Columns(i).ColumnName
            '檢查格式
            If MonthCompare.IndexOf("/") <> "4" OrElse MonthCompare.Split("/")(0).Length > 4 OrElse MonthCompare.Split("/")(1).Length > 2 Then
                MyObj.ShowMessage("The format should be yyyy/MM.")
                Return
            End If

            '檢查月份是否在版本內
            Dim MatchCount As Integer = 0
            For j As Integer = 1 To ScopeValue - 2 - 1
                If MonthCompare = TempDate.ToString("yyyy/MM") Then
                    MatchCount = MatchCount + 1
                    Exit For
                ElseIf MonthCompare = TempDate.AddMonths(j).Date.ToString("yyyy/MM") Then
                    MatchCount = MatchCount + 1
                    Exit For
                ElseIf MonthCompare = "" Then
                    Exit For
                End If
            Next

            If MatchCount = 0 AndAlso MonthCompare <> "" Then
                MyObj.ShowMessage(String.Format("{0} is out of scope.", dt.Columns(i).ColumnName))
                Return
            End If
        Next
        If dt.Columns.Count >= 3 And dt.Columns.Count <= ScopeValue Then
            For i As Integer = 0 To dt.Columns.Count - 1
                If i = 0 Then
                    dt.Columns(0).ColumnName = "SapCode"
                    FilterValue &= "convert(" & dt.Columns(0).ColumnName.ToString() & ",System.String)<>''"

                ElseIf i = 1 Then
                    dt.Columns(1).ColumnName = "SkuType"
                    FilterValue &= " or convert(" & dt.Columns(1).ColumnName.ToString() & ",System.String)<>''"

                ElseIf i >= 2 Then
                    GetMonth = dt.Columns(i).ColumnName.Split("/")(1)
                    'If Left(TableName.Replace(Me.HeaderTB & "SFReport", ""), 4) = dt.Columns(i).ColumnName.Split("/")(0) Then
                    '    dt.Columns(i).ColumnName = "Mon" & IIf(Left(GetMonth, 1) = "0", Right(GetMonth, 1), GetMonth)
                    'Else
                    '    dt.Columns(i).ColumnName = "Mon" & Int32.Parse(IIf(Left(GetMonth, 1) = "0", Right(GetMonth, 1), GetMonth) + 12)
                    'End If
                    'MonthString &= dt.Columns(i).ColumnName & ","
                    'FilterValue &= " or convert(" & dt.Columns(i).ColumnName.ToString() & ",System.String)<>''"
                    Dim YearGap As Integer = dt.Columns(i).ColumnName.Split("/")(0) - Left(TableName.Replace(Me.HeaderTB & "SFReport", ""), 4)
                    dt.Columns(i).ColumnName = "Mon" & (Int32.Parse(GetMonth) + YearGap * 12)
                    MonthString &= dt.Columns(i).ColumnName & ","
                    FilterValue &= " or convert(" & dt.Columns(i).ColumnName.ToString() & ",System.String)<>''"
                End If

            Next

            '新增Error欄位
            dt.Columns.Add("Error", System.Type.GetType("System.String"))

            Dim MyDefaultView As Data.DataView = dt.DefaultView
            MyDefaultView.RowFilter = FilterValue
            dt = MyDefaultView.ToTable()
        ElseIf dt.Columns.Count < 3 Then
            ErrorCount += 1
            MyObj.ShowMessage("Your column count should greater than 3.")
            Return
        Else
            ErrorCount += 1
            MyObj.ShowMessage("Your column count should smaller than " & ScopeValue & ".")
            Return
        End If

        '將欄位字串最後一個多的逗號去掉
        MonthString = MonthString.Substring(0, MonthString.Length - 1)

        '暫存匯入的SapCode+SkuType
        Dim MatchDT As New Data.DataTable
        MatchDT.Columns.Add("SapCodeAndSkuType", System.Type.GetType("System.String"))
        MatchDT.PrimaryKey = New DataColumn() {MatchDT.Columns(0)}

        '取出所有SapCode資料
        Dim AllSapCodeDT As Data.DataTable
        sql.Length = 0
        sql.AppendFormat("Select distinct SapCode from {0} ", TableName)
        AllSapCodeDT = dat.GetData(sql)
        AllSapCodeDT.PrimaryKey = New DataColumn() {AllSapCodeDT.Columns(0)}

        '取出有權限的SapCode資料
        Dim AuthSapCodeDT As Data.DataTable
        sql.Length = 0
        sql.AppendFormat("select distinct SapCode from ProductData p ")
        sql.AppendFormat("join DivisionBrandMappingView d on left(p.ProdHierarchy,2)=d.Brand ")
        If Me.ddlSignature.SelectedValue = "" Then
            sql.AppendFormat("and d.Division='{0}' ", Me.ddlDivision.SelectedValue)
        Else
            sql.AppendFormat("and d.Brand='{0}' ", Me.ddlSignature.SelectedValue)
        End If
        sql.AppendFormat("join RoleHierarchyMapping r on len(r.ProdHierarchy)=2 and d.Brand= r.ProdHierarchy ")
        sql.AppendFormat("join RoleUserMapping ru on r.RoleID =ru.RoleID ")
        sql.AppendFormat("where ru.userid='{0}' ", clsAuth.GetUserID())
        AuthSapCodeDT = dat.GetData(sql)
        AuthSapCodeDT.PrimaryKey = New DataColumn() {AuthSapCodeDT.Columns(0)}

        '取出有實際Sapcode+Channel存在的資料
        Dim SapCodeChannelDT As New Data.DataTable
        Dim cmanager As New ChannelManager
        Dim stManager As New SignatureManager
        sql.Length = 0
        sql.AppendFormat("select distinct SapCode,cv.Channel from ProductData p ")
        sql.AppendFormat("join ChannelView cv on left(p.ProdHierarchy,2)=cv.Signature ")
        If Me.ddlSignature.SelectedValue <> "" Then
            sql.AppendFormat("and cv.Signature='{0}' ", Me.ddlSignature.SelectedValue)
        Else
            sql.AppendFormat("and cv.Signature in ({0}) ", MyObj.JoinFormat(",", "'{0}'", stManager.GetSignatures(Me.ddlDivision.SelectedValue)))
        End If
        If Me.ddlCustomerGroup.SelectedValue <> "" Then
            sql.AppendFormat("and cv.Channel='{0}' ", Me.ddlCustomerGroup.SelectedValue)
        Else
            sql.AppendFormat("and cv.Channel in ({0}) ", MyObj.JoinFormat(",", "'{0}'", cmanager.GetChannelIDs(Me.ddlSignature.SelectedValue)))
        End If
        SapCodeChannelDT = dat.GetData(sql.ToString())
        SapCodeChannelDT.PrimaryKey = New DataColumn() {SapCodeChannelDT.Columns("SapCode"), SapCodeChannelDT.Columns("Channel")}

        '開始檢查資料
        Dim NewRow As DataRow
        Dim MatchtString As String = ""
        Dim SapCode, Skutype As String
        For k As Integer = 0 To dt.Rows.Count - 1
            '去掉TW
            dt.Rows(k)("SapCode") = Replace(dt.Rows(k)("SapCode").ToString(), MyObj.GetAreaCode(), "")
            SapCode = dt.Rows(k)("SapCode").ToString().Trim()
            Skutype = dt.Rows(k)("Skutype").ToString().Trim()

            MatchtString = SapCode & Skutype
            If MatchDT.Rows.Contains(MatchtString) Then
                '比對SapCode加MaterialType是否重複
                dt.Rows(k)("Error") = "The SAP code is repetition."
            Else
                If SapCode <> "" Then
                    NewRow = MatchDT.NewRow()
                    NewRow("SapCodeAndSkuType") = MatchtString
                    MatchDT.Rows.Add(NewRow)
                End If

                If Not AllSapCodeDT.Rows.Contains(SapCode) Then
                    '比對SapCode是否存在
                    dt.Rows(k)("Error") = "The SAP code doesn't exist."
                ElseIf Not AuthSapCodeDT.Rows.Contains(SapCode) Then
                    '比對SapCode是否在權限內
                    dt.Rows(k)("Error") = "The SAP code is out of your scope."
                ElseIf Me.ddlCustomerGroup.SelectedValue <> "" AndAlso SapcodeChannelDT.Rows.Find(New Object() {SapCode, Me.ddlCustomerGroup.SelectedValue}) Is Nothing Then
                    '比對SapCode是否可上傳至該Channel  Add By Angus 2011/10/3
                    dt.Rows(k)("Error") = "The SapCode's Channel doesn't exist."
                Else
                    '每個月份檢查
                    For Each mon As String In MonthString.Split(",")
                        dt.Rows(k)(mon) = dt.Rows(k)(mon).ToString().Replace(" ", "")
                        If dt.Rows(k)(mon).ToString() <> "" Then
                            '欄位值不可為負,且不可為非數字　
                            If IsNumeric(dt.Rows(k)(mon).ToString()) = False OrElse Double.Parse(dt.Rows(k)(mon).ToString()) < 0 Then
                                dt.Rows(k)("Error") = "Number should be positive."
                                Exit For
                            End If

                            'P.Allowance的欄位值不可超過100
                            If Skutype = "P.Allowance(%)" Then
                                If Double.Parse(dt.Rows(k)(mon).ToString()) > 100 Then
                                    dt.Rows(k)("Error") = "P.Allowance shouldn't over 100."
                                    Exit For
                                End If
                            End If
                        Else
                            '空值存0,Add By Angus 2011/3/18
                            dt.Rows(k)(mon) = 0
                        End If

                        'SapCode SkyType 不可為空
                        If dt.Rows(k)(mon).ToString() <> "" And SapCode = "" Then
                            dt.Rows(k)("Error") = "The SAP code column shouldn't be empty."
                            Exit For
                        ElseIf dt.Rows(k)("SapCode").ToString().Length > 8 Then
                            dt.Rows(k)("Error") = "The SAP code length shouldn't over then 8."
                            Exit For
                        ElseIf dt.Rows(k)(mon).ToString() <> "" And Skutype = "" Then
                            dt.Rows(k)("Error") = "The type column couldn't be empty."
                            Exit For
                        End If

                        '比對SkuType範圍
                        If Skutype <> "" Then
                            If Me.ddlUploadType.SelectedValue = "SellOut" Then
                                Select Case Skutype
                                    Case "Piping", "SellOut"
                                    Case "Listing Price"
                                    Case "Pre-Series(Local)", "PR(Local)", "Specimen(Local)", "Tester(Local)", "Trade Promo(Local)", "Training(Local)", "VIP(Local)" 'Transfer to PLV
                                    Case Else
                                        dt.Rows(k)("Error") = "The type is out of Type Parameter."
                                        Exit For
                                End Select
                            ElseIf Me.ddlUploadType.SelectedValue = "PLV" Then
                                Select Case Skutype
                                    Case "PM", "VIP", "TRADE", "Confirm"
                                    Case "STD"
                                    Case "Pre-Series(Local)", "PR(Local)", "Specimen(Local)", "Tester(Local)", "Trade Promo(Local)", "Training(Local)", "VIP(Local)" 'Transfer to PLV
                                    Case Else
                                        dt.Rows(k)("Error") = "The type is out of Type Parameter."
                                        Exit For
                                End Select
                            ElseIf Me.ddlUploadType.SelectedValue = "WF" Then
                                Select Case Skutype
                                    Case "Forecast Qty-S", "Forecast Qty-N", "Forecast Qty-P"
                                    Case Else
                                        dt.Rows(k)("Error") = "The type is out of Type Parameter."
                                        Exit For
                                End Select
                            Else
                                Select Case Skutype
                                    Case "sell-in-S", "sell-in-P", "P.Allowance(%)"
                                    Case "Listing Price"
                                    Case "STD"
                                    Case "Pre-Series(Local)", "PR(Local)", "Specimen(Local)", "Tester(Local)", "Trade Promo(Local)", "Training(Local)", "VIP(Local)" 'Transfer to PLV
                                    Case Else
                                        dt.Rows(k)("Error") = "The type is out of Type Parameter."
                                        Exit For
                                End Select
                            End If
                        End If
                    Next
                End If
            End If

            If dt.Rows(k)("Error").ToString() <> "" Then
                ErrorCount += 1
                Continue For
            End If

            '沒有錯誤則SHOW成功訊息
            'If dt.Rows(k)("Error").ToString() = "" Then
            '    dt.Rows(k)("Error") = "Upload Successful"
            'End If
        Next

        '有異常則不寫入資料
        If (ErrorCount > 0) Then
            MyObj.ShowMessage("Upload Failed.Data Error Count:" & ErrorCount)
        Else
            If dt.Rows.Count > 0 Then
                'Dim TempDT As Data.DataTable
                Dim MyRandom As New clsRandom
                Dim RandomCode As String = MyRandom.Generate(8)

                '新增欄位
                dt.Columns.Add("Version1", System.Type.GetType("System.String"))
                Dim Mydc As New DataColumn("ChannelID", System.Type.GetType("System.String"))
                Mydc.DefaultValue = Me.ddlCustomerGroup.SelectedValue
                dt.Columns.Add(Mydc)

                Mydc = New DataColumn("RandomCode", System.Type.GetType("System.String"))
                Mydc.DefaultValue = RandomCode
                dt.Columns.Add(Mydc)

                Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("connStr").ConnectionString)
                    cn.Open()
                    Using copy As New SqlBulkCopy(cn)
                        For i As Integer = 0 To dt.Columns.Count - 1
                            copy.ColumnMappings.Add(dt.Columns(i).ColumnName, dt.Columns(i).ColumnName)
                        Next
                        copy.DestinationTableName = "SFReportU"
                        copy.WriteToServer(dt)
                    End Using
                End Using

                dt.Columns.Remove("Version1")
                dt.Columns.Remove("ChannelID")
                dt.Columns.Remove("RandomCode")


                '設定需要寫入的Signature  Add By Angus 20110825
                '=================================================
                Dim sigList As New List(Of String)
                If Me.ddlSignature.SelectedValue = "" Then
                    For i As Integer = 0 To Me.ddlSignature.Items.Count - 1
                        If Me.ddlSignature.Items(i).Value <> "" Then
                            sigList.Add(Me.ddlSignature.Items(i).Value)
                        End If
                    Next
                Else
                    sigList.Add(Me.ddlSignature.SelectedValue)
                End If
                '=================================================

                Dim NewRandomCode As String = ""
                For i As Integer = 0 To sigList.Count - 1
                    NewRandomCode = RandomCode & i.ToString()
                    sql.Length = 0
                    sql.AppendFormat("Update SFReportU ")
                    sql.AppendFormat("set RandomCode='{0}' ", NewRandomCode)
                    sql.AppendFormat("where RandomCode='{0}' ", RandomCode)
                    sql.AppendFormat("and SapCode in ")
                    sql.AppendFormat("(")
                    sql.AppendFormat("  Select SapCode from ProductData ")
                    sql.AppendFormat("  where Left(ProdHierarchy,2)='{0}' ", sigList(i))
                    sql.AppendFormat(");")

                    sql.AppendFormat("exec ImportSalesForecast @RandomCode='{0}' ", NewRandomCode)
                    sql.AppendFormat(",@CustomerGroup='{0}' ", Me.ddlCustomerGroup.SelectedValue)
                    sql.AppendFormat(",@TableName='{0}' ", TableName)
                    sql.AppendFormat(",@Division='{0}' ", Me.ddlDivision.SelectedValue)
                    sql.AppendFormat(",@Signature='{0}' ", sigList(i))
                    sql.AppendFormat(",@EmployeeID='{0}' ", clsAuth.GetUserID())
                    'MyObj.WriteLog(sql.ToString())
                    dat.AccData(sql.ToString())
                Next

                MyObj.ShowMessage("Upload Successful.Data Success Count:" & dt.Rows.Count)
            Else
                MyObj.ShowMessage("Upload Failed.")
            End If

        End If

        '改顯示欄位名稱
        Dim CountAdd As Integer = 0
        Dim ErrorFilterValue As String = ""
        For a As Integer = 0 To dt.Columns.Count - 1
            If a = 0 Then
                dt.Columns(0).ColumnName = "sap code"

            ElseIf a = 1 Then
                dt.Columns(1).ColumnName = "type"

            ElseIf a >= 2 And a <> dt.Columns.Count - 1 Then
                If Int32.Parse(dt.Columns(a).ColumnName.Substring(3)) = MonthCount Then
                    dt.Columns(a).ColumnName = TempDate.ToString("yyyy/MM")
                Else

                    dt.Columns(a).ColumnName = TempDate.AddMonths(Int32.Parse(dt.Columns(a).ColumnName.Substring(3)) - MonthCount).ToString("yyyy/MM")
                End If
            ElseIf a = dt.Columns.Count - 1 Then

                dt.Columns(a).ColumnName = "Error"
                dt.Columns(a).SetOrdinal(0)

            End If

        Next

        dt.DefaultView.RowFilter = "convert(Error,System.String)<>''"
        GVDT = dt.DefaultView.ToTable

        Me.BindGV()
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub
#End Region

#Region "繫結資料"
    Protected Sub BindDDLUploadType()
        ddlUploadType.DataTextField = "Text"
        ddlUploadType.DataValueField = "Value"
        ddlUploadType.DataSource = MyObj.GetCodeMappingData("ForecastUpload", "UploadType")
        ddlUploadType.DataBind()
    End Sub

    Protected Sub BindVersion()
        Me.ddlVersion.Items.Clear()
        'If Me.HeaderTB = "WF_" Then
        Me.ddlVersion.Items.Add(New ListItem(DateTime.Now.ToString("yyyy/MM"), "SFReport" & DateTime.Now.ToString("yyyyMM")))
        Me.ddlVersion.Items.Add(New ListItem(DateTime.Now.AddMonths(1).ToString("yyyy/MM"), "SFReport" & DateTime.Now.AddMonths(1).ToString("yyyyMM")))
        'End If
        Me.ddlVersion.Items.Add(New ListItem(DateTime.Now.ToString("yyyy") & "Budget", "SFReport" & DateTime.Now.ToString("yyyy") & "B"))
        Me.ddlVersion.Items.Add(New ListItem(DateTime.Now.ToString("yyyy") & "Trend", "SFReport" & DateTime.Now.ToString("yyyy") & "T"))
        Me.ddlVersion.Items.Add(New ListItem(DateTime.Now.AddYears(1).ToString("yyyy") & "Budget", "SFReport" & DateTime.Now.AddYears(1).ToString("yyyy") & "B"))
        Me.ddlVersion.SelectedIndex = -1
    End Sub

    Private Sub BindDDLDivision()
        Dim ddlControl As DropDownList = Me.ddlDivision
        Dim dvManager As New DivisionManager

        ddlControl.DataTextField = "Division"
        ddlControl.DataValueField = "Division"
        ddlControl.DataSource = dvManager.GetAllDivision()
        ddlControl.DataBind()
    End Sub

    Private Sub BindDDLSignature()
        Dim ddlControl As DropDownList = Me.ddlSignature
        Dim stManager As New SignatureManager

        ddlControl.DataTextField = "Description"
        ddlControl.DataValueField = "Signature"
        ddlControl.DataSource = stManager.GetSignatureNoNewCategories(Me.ddlDivision.SelectedValue)
        ddlControl.DataBind()
        ddlControl.Items.Insert(0, MyObj.GetDDLSelectAllItem())
    End Sub

    Protected Sub BindDDLEdition()
        ddlEdition.DataTextField = "Text"
        ddlEdition.DataValueField = "Value"
        ddlEdition.DataSource = MyObj.GetCodeMappingData("Product", "Version")
        ddlEdition.DataBind()
        ddlEdition.Items.Insert(0, MyObj.GetDDLSelectAllItem())
        'ddlEdition.SelectedValue = "S"
    End Sub

    Protected Sub BindDDLCustomerGroup()
        ddlCustomerGroup.Items.Clear()
        'If Me.ddlSignature.SelectedValue <> "" Then
        Dim cmanager As New ChannelManager
        ddlCustomerGroup.DataSource = cmanager.GetAllByDivision(Me.ddlDivision.SelectedValue, Me.ddlSignature.SelectedValue)
        ddlCustomerGroup.DataTextField = "ChannelName"
        ddlCustomerGroup.DataValueField = "Channel"
        ddlCustomerGroup.DataBind()
        'End If
        ddlCustomerGroup.Items.Insert(0, MyObj.GetDDLSelectAllItem())
    End Sub

    Protected Sub BindGV()
        gv.DataSource = GVDT
        gv.DataBind()
        If gv.Rows.Count > 0 Then
            gv.Visible = True
        Else
            gv.Visible = False
        End If
    End Sub
#End Region

#Region "屬性"
    Public Property GVDT() As Data.DataTable
        Get
            Return ViewState("GVDT")
        End Get
        Set(ByVal value As Data.DataTable)
            ViewState("GVDT") = value
        End Set
    End Property

    Public ReadOnly Property HeaderTB() As String
        Get
            Select Case Me.ddlUploadType.SelectedValue
                Case "SellOut"
                    Return "SO_"
                Case "PLV"
                    Return "PLV_"
                Case "WF"
                    Return "WF_"
                Case Else
                    Return ""
            End Select
        End Get
    End Property
#End Region

End Class
